<template>
  <div v-loading="loading">
    <el-row class="gl_mb_10">
      <el-col :span="21">
        <el-button size="mini" :type="currentType ? 'primary' : ''" @click="handleSelect('ApproveSuccess')">已有的分站赛</el-button>
        <el-button size="mini" :type="!currentType ? 'primary' : ''" @click="handleSelect('')">申请的分站赛</el-button>
      </el-col>
    </el-row>
    <el-row :gutter="15">
      <template v-if="raceData.length > 0">
        <el-col v-for="item in raceData" :key="item.id" :span="12" class="gl_my_5">
          <el-card shadow="hover" :body-style="{ padding: '10px', position: 'relative' }">
            <el-row :gutter="10">
              <el-col :span="6" align="center">
                <el-row>
                  <show-avatar
                    :src="getStaticAvatarUrl(item.imagePath)"
                    width="76px"
                    height="76px"
                    shape="circle"
                  />
                </el-row>
                <el-row>
                  <el-col class="gl_mt_15">
                    <el-button size="mini" type="primary" @click="showAddMemberDialog(item)">编辑</el-button>
                  </el-col>
                  <el-col class="gl_mt_15">
                    <el-button size="mini" @click="gotoBackStage(item)">后台</el-button>
                  </el-col>
                </el-row>
              </el-col>
              <el-col :span="18">
                <div class="gl_ft_weight label_title">{{ item.name }}</div>
                <div class="gl_mb_5 gl_ellipsis">
                  <span class="label_name">比赛时间：</span>
                  <span class="label_content">{{ item.startTime ? item.startTime.slice(0, 10) : '-' }} {{ item.endTime ? '至 ' + item.endTime.slice(0, 10) : '' }}</span>
                </div>
                <div class="gl_mb_5 gl_ellipsis">
                  <span class="label_name">认证等级：</span>
                  <span class="label_content">{{ item.competitionCertificationLevelName }}</span>
                </div>
                <div class="gl_mb_5 gl_ellipsis">
                  <span class="label_name">比赛地址：</span>
                  <span class="label_content">{{ item.address }}</span>
                </div>
                <div class="gl_mb_5 gl_ellipsis">
                  <span class="label_name">负责人：</span>
                  <span class="label_content">{{ item.responsiblePersonName }}</span>
                </div>
                <div class="gl_mb_5 gl_ellipsis">
                  <span class="label_name">联系电话：</span>
                  <span class="label_content">{{ item.responsiblePersonPhone }}</span>
                </div>
                <div class="gl_mb_5 gl_ellipsis">
                  <span class="label_name">申请机构：</span>
                  <span class="label_content">{{ item.enterDelegationName }}</span>
                </div>
              </el-col>
            </el-row>
            <div class="status_img">
              <img :src="approveStatusImg[item.approveStatusCode]">
            </div>
          </el-card>
        </el-col>
      </template>
      <el-col v-if="raceData.length > 0" :span="24">
        <div align="center" class="gl_pt_10">
          <el-pagination :current-page="qo.Page" :page-size="qo.MaxResultCount" :total="totalPage" layout="total,sizes,prev,pager,next,jumper" :page-sizes="[9, 18, 27, 36]" @size-change="sizeChange" @current-change="pageIndexChange" />
        </div>
      </el-col>
      <el-col v-else :span="24">
        <div class="gl_noData">
          <p>暂无数据</p>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { mapState, mapActions } from 'vuex';

import imgReview from '@/assets/images/league/review.png';
import imgTurndown from '@/assets/images/league/turndown.png';
import imgCompleted from '@/assets/images/league/completed.png';
// import {
//   Api_GET_EventsManagementCompetitionRequestMyCompetitionRequestQO
// } from '@/lib/form/game/swaggerForm';
// import {
//   api_GET_EventsManagementCompetitionRequestMyCompetitionRequest // 分页查询我的分站赛申请列表（C端）
// } from '@/extend/api/gameswaggerApi/app';

export default {
  data() {
    return {
      currentType: '',
      qo: new Api_GET_EventsManagementCompetitionRequestMyCompetitionRequestQO(),
      raceData: [],
      totalPage: 0,
      loading: false,
      delegationId: '',
      approveStatusImg: { // 审核状态对应的图片
        NotApproved: imgReview,
        ApproveSuccess: imgCompleted,
        ApproveFailed: imgTurndown,
        UnderReview: imgReview
      },
      tagsColorTheme: ['info', 'primary', 'success', 'danger', 'primary']
    };
  },
  computed: {
    ...mapState({
      currentUserType: state => state.user.currentUserType,
      dict: state => state.dict.dict,
      cache: state => state.dict.cache,
      dictAll: state => state.dict.dictAll
    })
  },
  created() {
    this.qo.MaxResultCount = 9;
    this.getDictByType(['district']);
    this.getDataPage();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict', getDictByType: 'dict/getDictByType' }),
    handleSelect(code) {
      this.currentType = code;
      this.qo.ApproveStatusCode = code;
      this.getDataPage();
    },
    // 获取团体下的人员
    getDataPage(page) {
      if (!this.currentUserType.delegationId) return;
      this.loading = true;
      this.qo.Page = page || 1;
      this.qo.SkipCount = (this.qo.Page - 1) * this.qo.MaxResultCount;
      this.qo.DelegationId = this.currentUserType.delegationId;
      api_GET_EventsManagementCompetitionRequestMyCompetitionRequest(this.qo).then(res => {
        this.raceData = res.items;
        this.raceData.map(item => {
          if (item.approveStatusCode) {
            this.dictAll.competitionApproveStatus.map((jtem, index) => {
              if (item.approveStatusCode === jtem.code) {
                item.approveStatusCodeName = jtem.value;
                item.approveStatusCodeType = index;
              }
            });
          }
        });
        console.log('this.existen', this.raceData);
        this.totalPage = res.totalCount;
        this.loading = false;
      });
    },
    sizeChange(MaxResultCount) {
      this.qo.MaxResultCount = MaxResultCount;
      this.getDataPage();
    },
    pageIndexChange(currentPage) {
      this.getDataPage(currentPage);
    },
    // 编辑分站赛信息
    showAddMemberDialog(info) {
      console.log('info', info);
    },
    // 跳转到后台
    gotoBackStage(info) {
      console.log('hhhh', info);
    },
    // 头像回显
    getStaticAvatarUrl(relativeUrl) {
      if (relativeUrl) {
        return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
      } else {
        return require('@/assets/images/face_default.png');
      }
    }
  }
};
</script>
<style scoped>
.label_title {
  height: 48px;
  margin: 0 0 2px;
  padding: 0;
  font-size: 18px;
  line-height: 24px;
  color: #000;
  font-weight: 600;
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.label_name {
  font-size: 14px;
  /* font-weight: bold;
  color: rgba(0, 0, 0, 0.8); */
  color: #828282;
  display: inline-block;
  width: 4em;
  margin-right: 26px;
  text-align: right;
  vertical-align: middle;
  color: #828282;
}
.label_content {
    display: inline-block;
    vertical-align: middle;
    font-size: 14px;
    color: #353434;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.status_img {
  position: absolute;
  right: 10px;
  bottom: 5px;
}
</style>
